package com.jar.exercise.集合和数据结构.arrayList的底层实现.手写arraylist;

/**
 * @author ZhangShengHao
 * @className MyArrayList
 * @description TODO
 * @date 2020/2/26 12:45
 */
public class MyArrayList {
	private int size;
	private Object[] objects;

	public MyArrayList() {
		objects = new Object[10];
	}

	public void add(Object o) {
		if (size >= objects.length) {
			Object[] newObjects = new Object[this.objects.length * 2];
			System.arraycopy(objects, 0, newObjects, 0, objects.length);
			objects = newObjects;
		}
		objects[size++] = o;
	}

	public static void main(String[] args) {
		MyArrayList myArrayList = new MyArrayList();
		myArrayList.add("1");
		myArrayList.add("1");
		myArrayList.add("1");
		myArrayList.add("1");
		myArrayList.add("1");
		myArrayList.add("1");
		myArrayList.add("1");
		myArrayList.add("1");
		myArrayList.add("1");
		myArrayList.add("10");
		myArrayList.add("11");
	}
}
